package com.pagepub.expo.manager;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.pagepub.expo.dao.CorpCatalogDao;
import com.pagepub.expo.entity.AppRole;
import com.pagepub.expo.entity.CorpCatalog;
import com.pagepub.expo.entity.CorpCommpany;
import com.pagepub.expo.entity.IdName;

@Service
@Transactional
@RemotingDestination(channels = { "my-amf", "my-secure-amf" })
public class CorpCatalogMng {
	@Autowired
	private CorpCatalogDao corpCatalogDao;


	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<CorpCatalog> findAll() {
		return corpCatalogDao.findAll();
	}
	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public int getCount(Map<String, String> param){
		return corpCatalogDao.getCount(param);
	}
	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<CorpCatalog> findByPage(int currentPage,int pageSize,Map<String, String> param){
		return corpCatalogDao.findByPage(currentPage, pageSize, param);
	}
	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<CorpCatalog> getCorpCatalogByParentId(String parentId){
		return corpCatalogDao.getCorpCatalogByParentId(parentId);
	}


	@RemotingInclude
	public CorpCatalog add(CorpCatalog corpCatalog) {
		corpCatalogDao.insert(corpCatalog);
		return corpCatalogDao.findById(new Long(corpCatalog.getId()));
	}

	@RemotingInclude
	public Long remove(Long id) {
		corpCatalogDao.delete(id);
		return id;
	}
	
	@RemotingInclude
	public CorpCatalog findById(Long id){
		return corpCatalogDao.findById(id);
	}

	@RemotingInclude
	public CorpCatalog update(CorpCatalog corpCatalog) {
		corpCatalogDao.update(corpCatalog);
		return corpCatalogDao.findById(new Long(corpCatalog.getId()));
	}
	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<IdName> findIdNames(){
		return corpCatalogDao.findIdNames();
	}
}
